package com.cxria.springboottest.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage("com.cxria.springboottest")).paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		StringBuilder description = new StringBuilder();
		description.append("\"正常\", \"0000\", \"send success\"&#10\n");
		description.append("\"用户没有登陆\", \"1001\", \"user not login\"&#10\n");
		description.append("\"用户角色\", \"1002\", \"user role error\"&#10\n");
		description.append("\"用户权限错误\", \"1003\", \"user authority error\"&#10\n");
		description.append("\"用户鉴权错误（密码或用户名不匹配）\", \"1004\", \"user incorrect credentials error\"&#10\n");
		description.append("\"用户不能被删除错误（第一个管理员）\", \"1005\", \"user is not delete error\"&#10\n");
		description.append("\"角色不能被删除错误（第一个管理员角色）\", \"1006\", \"role is not delete error\"&#10\n");
		description.append("\"数据已存在\", \"2001\", \"data already exists error\"&#10\n");
		description.append("\"数据保存错误\", \"2002\", \"data save error\"&#10\n");
		description.append("\"数据验证错误\", \"2003\", \"data vidlation error\"&#10\n");
		description.append("\"表格数据错误\", \"3001\", \"xls data error\"&#10\n");
		description.append("\"不是xls文件错误\", \"3002\", \"not is xls file error\"&#10\n");
		description.append("\"未选择原始数据错误\", \"4001\", \"unselected raw data\"&#10\n");
		description.append("\"未知错误\", \"9999\", \"unkunwn error\"&#10\n");
		return new ApiInfoBuilder().title("内部管理系统api").description(description.toString()).version("1.1").build();
	}

}